package com.example.cart_system.service.Impl;

import com.example.cart_system.mapper.CartMapper;
import com.example.cart_system.pojo.Cart;
import com.example.cart_system.pojo.GoodsInfo;
import com.example.cart_system.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class CartServiceImpl implements CartService {
    @Autowired
    private CartMapper cartMapper;

    @Override
    public Boolean addCart(Cart cart) {
        String good = cartMapper.getCartId(cart.getGid(), cart.getUsrid());
        if (good == null || good.isEmpty()) {
            cartMapper.addCart(cart);
            return true;
        }
        cartMapper.addCnn(cart);
        return false;
    }

    @Override
    public Boolean addCnn(Cart cart) {
        cartMapper.addCnn(cart);
        return true;
    }

    @Override
    public Boolean reduceCnn(Cart cart) {
        cartMapper.reduceCnn(cart);
        return true;
    }

    @Override
    public List<GoodsInfo> getCartList(String usrid) {
        return cartMapper.getCartList(usrid);
    }

    @Override
    public Boolean removeCart(String gid, String usrid) {
        cartMapper.removeCart(gid, usrid);
        return true;
    }

    @Override
    public void clearCart(String usrid) {
        cartMapper.deleteCart(usrid);
    }
}
